package com.house365.core.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.text.TextUtils;

/**
 * @author py
 * @date 2012-6-4
 * @comment
 */
public class RegexUtil {
	public static boolean isNumber(String s) {
		Pattern pattern = Pattern.compile("\\d*", Pattern.CASE_INSENSITIVE);
		return pattern.matcher(s).matches();
	}

	public static boolean isNumberWithLen(String s, int len) {
		Pattern pattern = Pattern.compile("\\d{" + len + "}",
				Pattern.CASE_INSENSITIVE);
		return pattern.matcher(s).matches();
	}

	
	public static boolean isCharacter(String s) {
		Pattern pattern = Pattern.compile("\\w*", Pattern.CASE_INSENSITIVE);
		return pattern.matcher(s).matches();
	}

	public static boolean isCharacterWithLen(String s, int len) {
		Pattern pattern = Pattern.compile("\\w{" + len + "}",
				Pattern.CASE_INSENSITIVE);
		return pattern.matcher(s).matches();
	}

	public static boolean isNumCharCombinationWithLen(String s, int minLen, int maxLen) {
		Pattern pattern = Pattern.compile("[A-Za-z0-9]{" + minLen + "," + maxLen+ "}",
				Pattern.CASE_INSENSITIVE);
		return pattern.matcher(s).matches();
	}
	
	public static boolean isMobileNumber(String mobiles) {
		if(!TextUtils.isEmpty(mobiles)){
			Pattern p = Pattern
//					.compile("^((13[0-9])|(15[^4,\\D])|(18[0,1,2,3,5-9]))\\d{8}$");
//			.compile("^(((13[0-9])|147|(15[^4,\\D])|(18[0-9]|(17[0,6-8]))\\d{8}))|((170[0,5,9])\\d{7})$");
					.compile("^\\d{11}$");
			Matcher m = p.matcher(mobiles);
			return m.matches();
		}else{
			return false;
		}
	}
	public static boolean isChineseLength(String str, int minlen, int maxlen) {
		String regEx = "[\\u4e00-\\u9fa5]{"+minlen+","+maxlen+"}";
		Pattern p = Pattern.compile(regEx);
		Matcher m = p.matcher(str);
		return m.matches();
	}
}
